<template>
  <div class="app-wrapper">
    <headerTitle
      :titleList="titleList"
      :hideButton="true"
    />
    <div class="app-container">
      <div class="containerMain">
        <el-header>
          <div class="header-group">
            <!-- <div>
              <span>{{entName}}</span>
              <span>{{entNum}}</span>
            </div> -->
            <div>
              <el-button type="primary" size="small" @click="exportFn">导出</el-button>
              <!-- <el-button type="primary" size="mini" @click="showBitchAdd">批量新增机构</el-button> -->
              <el-button type="primary" size="small" @click="showAdd">新增机构</el-button>
            </div>
          </div>
        </el-header>
        <div class="contains">
          <tree-table
            ref="recTree"
            :list.sync="treeDataSource"
            @actionFunc="updateFunc"
            @deleteFunc="deleteFunc"
            @handlerExpand="handlerExpand"
          ></tree-table>
        </div>
      </div>
    </div>
    <!-- 新增编辑机构模态框-->
    <el-dialog
      :title="title"
      :visible.sync="dialogFormVisible"
      @close="resets"
      :close-on-press-escape="false"
      :close-on-click-modal="false"
    >
      <el-form :model="form" ref="form" :rules="rulesList" style="width:500px;">
        <el-form-item label="机构级别" v-if="levelShow=='2'" :label-width="formLabelWidth">
          <span>三级机构</span>
        </el-form-item>
        <el-form-item label="机构级别" v-if="levelShow=='1'" :label-width="formLabelWidth">
          <el-radio
            v-model="form.level"
            label="2"
            @change="handelLevel"
            :disabled="form.addOrUpdate==2"
          >二级机构</el-radio>
          <el-radio
            v-model="form.level"
            label="3"
            @change="handelLevel"
            :disabled="form.addOrUpdate==2"
          >三级机构</el-radio>
        </el-form-item>
        <el-form-item label="机构编号" :label-width="formLabelWidth" v-show="form.addOrUpdate==2">
          <span>{{form.code}}</span>
        </el-form-item>
        <el-form-item label="机构名称" :label-width="formLabelWidth" prop="name">
          <el-input size="small" v-model="form.name" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item
          label="上级机构"
          :label-width="formLabelWidth"
          v-show="form.level==3"
          prop="parentId"
        >
          <el-select
            v-model="form.parentId"
            filterable
            placeholder="请选择"
            style="width:380px;"
            @change="getThreeSubId"
            :disabled="form.addOrUpdate==2"
            size="small"
          >
            <el-option v-for="item in entlist" :key="item.id" :label="item.name" :value="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="地域归属" :label-width="formLabelWidth" v-if="form.level==2" prop="area">
          <el-cascader
            :disabled="form.addOrUpdate==2&&form.revise==2"
            :options="areas"
            change-on-select
            v-model="form.area"
            :props="props"
            style="width:380px;"
            size="small"
          ></el-cascader>
        </el-form-item>
        <el-form-item label="机构业务号" :label-width="formLabelWidth" prop="subid">
          <el-input size="small" v-model="form.subid" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label :label-width="formLabelWidth" v-if="form.level==2" prop>
          <el-checkbox v-model="operate">独立子企业</el-checkbox>
          <span style="font-size:12px;">（本功能适用于委外、代理、总分公司出账企业开户场景，请慎用）</span>
        </el-form-item>
        <el-form-item
          label="绑定运营点"
          :label-width="formLabelWidth"
          v-if="form.level==2&&operate==true"
          prop="operateId"
        >
          <el-select size="small" v-model="form.operateId" filterable clearable placeholder="请选择">
            <el-option
              v-for="item in operateOptions"
              :key="item.operateId"
              :label="item.operateName + item.operateId"
              :value="item.operateId"
            >{{item.operateId + "&nbsp;&nbsp;|&nbsp;&nbsp;" + item.operateName}}</el-option>
            <!-- :filter-method="filterMethod" -->
          </el-select>
        </el-form-item>
        <el-form-item
          label="计费企业"
          :label-width="formLabelWidth"
          v-if="form.level==2&&operate==true&&!billShow"
          prop="chargeType"
        >
          <el-select size="small" v-model="form.chargeType" placeholder="请选择" @change="billChange">
            <el-option
              v-for="item in billOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
          <div
            v-show="form.chargeType==1"
            style="height: 33px;line-height:33px;"
          >计费企业ID:由JFQY+企业编号+机构编号组成;计费企业名称:同机构名称</div>
          <div v-show="form.chargeType==2">
            <el-select size="small" v-model="form.chargeNum" filterable placeholder="请选择">
              <el-option
                v-for="item in billEntOptions"
                :key="item.chargeNum"
                :label="item.chargeEntName + item.chargeNum"
                :value="item.chargeNum"
              >{{item.chargeEntName + item.chargeNum}}</el-option>
            </el-select>
          </div>
          <div v-show="form.chargeType==3">
            <el-input
              type="text"
              placeholder="请输入计费企业ID"
              size="small"
              onkeyup="value=value.replace(/[^\d]/g,'')"
              v-model="form.chargeNum"
            ></el-input>
            <el-input
              type="text"
              placeholder="请输入计费企业名称"
              size="small"
              onkeyup="this.value=this.value.replace(/[^\u4e00-\u9fa5]/g,'')"
              onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\a-zA-Z\u4E00-\u9FA5]/g,''))"
              v-model="form.chargeEntName"
            ></el-input>
            <!-- onkeyup="value=form.chargeEntName.replace(/[^\a-zA-Z\u4E00-\u9FA5]/g,'')" -->
          </div>
        </el-form-item>
        <el-form-item
          label="计费企业"
          :label-width="formLabelWidth"
          v-if="form.level==2&&operate==true&&billShow"
          prop="chargeType"
        >
          <el-input
            style="margin-bottom:5px"
            size="small"
            v-model="form.chargeNum"
            type="text"
            disabled
          ></el-input>
          <el-input size="small" v-model="form.chargeEntName" type="text" disabled></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false" size="mini">取 消</el-button>
        <el-button type="primary" @click="checkVlue" size="mini">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 批量新增机构模态框-->
    <el-dialog
      title="批量新增机构"
      :visible.sync="dialogBitchAddFormVisible"
      :lock-scroll="true"
      @close="clearFile"
    >
      <el-form :model="formdata" style="width:400px;">
        <el-form-item label="机构级别" :label-width="formLabelWidth">
          <el-radio v-model="formdata.level" label="2" @change="handelBitchLevel">二级机构</el-radio>
          <el-radio v-model="formdata.level" label="3" @change="handelBitchLevel">三级机构</el-radio>
        </el-form-item>
        <el-form-item label="文件导入" :label-width="formLabelWidth">
          <el-upload
            class="upload-file"
            action="/apis/admin/ent/organ/import"
            :data="formdata"
            ref="newupload"
            multiple
            :limit="1"
            :on-exceed="handleExceed"
            :auto-upload="false"
            :http-request="uploadSectionFile"
          >
            <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
            <a
              style="margin-left: 10px;"
              size="small"
              type="success"
              v-show="formdata.level==2"
              href="download/twoOrgan.xls"
              download
            >批量二级机构模板</a>
            <a
              style="margin-left: 10px;"
              size="small"
              type="success"
              v-show="formdata.level==3"
              href="download/threeOrgan.xls"
              download
            >批量三级机构模板</a>
          </el-upload>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogBitchAddFormVisible = false" size="mini">取 消</el-button>
        <el-button type="primary" @click="bitchAdd" size="mini">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import HeaderTitle from "@/components/Headertitle/index";
import Qs from "qs";
import treeTable from "@/components/Treetable/index";
import { translateDataToTree } from '@/utils'
import { fetchEntName, fetchList, fetchOrganList, fetchArealist, fetchSubId, fetchThreeSubId, fetchEditInfo } from "@/api/systemapi/organ";
export default {
  data() {
    return {
      titleList: [{ title: "机构管理" }],
      //校验1规则
      rules1: {
        name: [
          { required: true, message: "机构名称不能为空", trigger: "blur" },
          {
            min: 3,
            max: 32,
            pattern: /^[\u4e00-\u9fa5a-zA-Z0-9]{3,32}$/,
            message: "机构名称只支持3-32位中英文和数字填写",
            trigger: "blur"
          }
        ],
        area: [
          {
            required: true,
            message: "地域属性不能为空",
            trigger: "change"
          }
        ],
        subid: [
          {
            required: true,
            message: "机构业务号不能为空"
          },
          {
            min: 1,
            max: 20,
            pattern: /^[a-zA-Z0-9]{1,20}$/,
            message: "机构业务号只支持1-20位英文和数字填写",
            trigger: "change"
          }
        ],
        operateId: [
          {
            required: true,
            message: "运营点不能为空",
            trigger: "change"
          }
        ]
      },
      //校验2规则
      rules2: {
        name: [
          { required: true, message: "机构名称不能为空", trigger: "blur" },
          {
            min: 3,
            max: 32,
            message: "机构名称只支持3-32位中英文和数字填写",
            trigger: "blur"
          }
        ],
        parentId: [
          { required: true, message: "上级机构不能为空", trigger: "change" }
        ],
        subid: [
          {
            required: true,
            message: "机构业务号不能为空"
          },
          {
            min: 1,
            max: 20,
            pattern: /^[a-zA-Z0-9]{1,20}$/,

            message: "机构业务号只支持1-20位英文和数字填写",
            trigger: "change"
          }
        ]
      },
      title: "新增机构",
      treeDataSource: [
        { id: 8,
          name: "默认一级机构",
          code: "101",
          subId: "101",
          level: 1,
          parentId: 0,
          entNum: "201",
          enable: 1,
          updateId: 15,
          updateTime: "2020-03-13 14:46:53",
          createId: 15,
          createTime: "2020-03-13 14:46:53"},
          {
            id: 9,
          name: "默认二级机构",
          code: "201",
          subId: "201",
          level: 2,
          parentId: 8,
          entNum: "201",
          enable: 1,
          updateId: 15,
          updateTime: "2020-03-13 14:46:53",
          createId: 15,
          createTime: "2020-03-13 14:46:53",
          },
          {
            id: 10,
          name: "默认三级机构",
          code: "30101",
          subId: "30101",
          level: 3,
          parentId: 9,
          entNum: "201",
          enable: 1,
          updateId: 15,
          updateTime: "2020-03-13 14:46:53",
          createId: 15,
          createTime: "2020-03-13 14:46:53",
          }

      ],
      areas: [],
      props: {
        value: "id",
        label: "name",
        children: "children"
      },
      entNum: "2131313",
      entName: "河北移动总公司",
      dialogFormVisible: false, //新增模态框
      dialogBitchAddFormVisible: false, //批量新增模态框
      entlist: [],
      form: {
        addOrUpdate: "1", //新增或是编辑 1新增2编辑
        level: "2",
        name: "",
        id: "",
        code: "",
        area: [],
        parentId: "",
        subid: "",
        revise: 1,
        chargeType: "",
        operateId: "",
        chargeNum: "", //计费ID
        chargeEntName: "" //计费企业名称
      },
      formLabelWidth: "120px",
      formdata: {
        level: "2"
      }, //上传文件携带的参数
      operate: false, //
      operateOptions: [],
      billOptions: [
        { value: "1", label: "自动生成新计费企业ID和名称" },
        { value: "2", label: "使用已有企业ID和名称" },
        { value: "3", label: "自定义新企业ID和名称" }
      ],
      billEntOptions: [], //计费企业
      billShow: false, //计费选择
      optionsCopy: [],
      levelShow: "",// 记录当前登录的是几级机构
    };
  },
  components: {
    treeTable,
    HeaderTitle
  },

  computed: {
    rulesList: function() {
      if (this.form.level == 2) {
        return this.rules1;
      } else if (this.form.level == 3) {
        return this.rules2;
      }
    }
  },
  created() {
    // let id = this.getQueryString("id") || 2019071000;
    // fetchEntName(id).then(response => {
    //   this.$nextTick(() => {
    //     this.entName = response.data.data;
    //   });
    // });
    // console.log(id, this.entName, "id");
    // this.entNum = id;
    this.getTreeData();
    this.getArealist();
  },
  methods: {
    backFn() {
      this.$router.push({ path: "/system/organ/index" });
    },
    resets() {
      this.$nextTick(() => {
        //等待dom同步后打开模态框
        this.$refs["form"].clearValidate();
        this.$refs["form"].resetFields(); //此方法需要模态框加载完成后才可以执行
      });
    },
    getQueryString(name) {
      var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
      var r = window.location.search.substr(1).match(reg);
      if (r != null) return unescape(r[2]);
      return null;
    },
    treeData(data) {
      let cloneData = JSON.parse(JSON.stringify(data)); // 对源数据深度克隆
      let tree = cloneData.filter(father => {
        //循环所有项
        let branchArr = cloneData.filter(child => {
          return father.id == child.parentId; //返回每一项的子级数组
        });
        if (branchArr.length > 0) {
          father.children = branchArr; //如果存在子级，则给父级添加一个children属性，并赋值
        }
        return father.parentId == 0; //返回第一层
      });
      return tree; //返回树形数据
    },
    getTreeData() {
      fetchList().then(response => {
        this.$nextTick(() => {
          this.treeDataSource = translateDataToTree(response.rows);
          console.log(this.treeDataSource);
        });
      });
    },
    //获取上级机构列表
    getOrganList(id) {
      fetchOrganList(this.entNum).then(response => {
        //   console.log(response.data.data);
        this.$nextTick(() => {
          this.entlist = response.data.data;
        });
      });
    },
    //初始化获取省市县
    getArealist() {
      fetchArealist(0).then(response => {
        // console.log(response.data.data);
        this.$nextTick(() => {
          this.areas = this.treeData(response.data.data);
          this.areas.unshift({
            code: "999999",
            firstLetter: "B",
            id: 0,
            level: 1,
            name: "不启用",
            parentId: -1,
            vcode: "V999999999999"
          });
          console.log(this.areas);
        });
      });
    },
    getSubId(entNum, level) {
      fetchSubId(this.entNum).then(response => {
        //   console.log(response.data.data);
        this.$nextTick(() => {
          if (level == 2) {
            this.form.subid = response.data.data.twoSubid - 0;
          }
          // if (level == 3) {
          //   this.form.subid = response.data.data.threeSubid-0;
          // }
        });
      });
    },
    getThreeSubId() {
      fetchThreeSubId(this.form.parentId, this.entNum).then(response => {
        //   console.log(response.data.data);
        this.$nextTick(() => {
          if (this.form.level == 3) {
            this.form.subid = response.data.data.threeSubid - 0;
          }
        });
      });
    },
    handleItemChange(val) {
      console.log(val, 1111110);
    },
    showAdd() {
      this.operate = false;
      this.billShow = false;
      this.title = "新增机构";
      this.form = {
        addOrUpdate: "1", //新增或是编辑 1新增2编辑
        level: "2",
        name: "",
        code: "",
        id: "",
        area: [],
        parentId: "",
        subid: ""
      };
      this.getSubId(this.entNum, 2);
      //   this.getOrganList();
      //   if (this.$refs["form"]) {
      //     this.$refs["form"].resetFields();
      //   }
      this.$nextTick(() => {
        //等待dom同步后打开模态框
        this.$refs["form"].clearValidate();
        //this.$refs["form"].resetFields(); //此方法需要模态框加载完成后才可以执行
      });
      this.getOperate();
      this.dialogFormVisible = true;
    },
    showBitchAdd() {
      this.clearFile();
      this.formdata.level = "2";
      this.dialogBitchAddFormVisible = true;
    },
    bitchAdd() {
      if (this.$refs.newupload) {
        if (this.$refs.newupload.uploadFiles.length < 1) {
          this.$message({
            type: "warning",
            message: "请先选择文件！"
          });
          return false;
        }
      }
      this.$refs.newupload.submit();
    },
    //上传及校验文件
    uploadSectionFile(param) {
      var fileObj = param.file;
      console.log(fileObj);
      // FormData 对象
      var form = new FormData();
      // 文件对象
      form.append("file", fileObj);
      form.append("entNum", this.entNum);
      form.append("level", this.formdata.level);
      this.axios.post("/admin/ent/organ/check", form).then(res => {
        if (res.data.code == 0) {
          this.uploadFile(form);
        } else {
          this.$message({
            type: "error",
            message: res.data.msg
          });
        }
      });
    },
    uploadFile(form) {
      this.axios.post("/admin/ent/organ/import", form).then(res => {
        if (res.data.code == 0) {
          this.$message({
            type: "success",
            message: res.data.msg
          });
          this.dialogBitchAddFormVisible = false;
          this.getTreeData();
        } else {
          this.$message({
            type: "error",
            message: res.data.msg
          });
        }
      });
    },
    //关闭模态框，清空数据
    clearFile() {
      //console.log(this.$refs);
      if (this.$refs.newupload) {
        this.$refs.newupload.clearFiles();
        this.$refs.newupload.uploadFiles.length = 0;
        this.formdata.level = "2";
      }
    },
    add() {
      console.log(this.form);
    },
    update() {},
    //批量新增切换机构
    handelBitchLevel() {
      if (this.$refs.newupload) {
        this.$refs.newupload.clearFiles();
        this.$refs.newupload.uploadFiles.length = 0;
      }
    },
    //添加机构 切换机构级别
    handelLevel(val) {
      console.log(val);

      this.form = {
        ...this.form,
        ...{
          id: "",
          area: [],
          parentId: "",
          subid: ""
        }
      };
      if (val == 3) {
        //当前选择是三级,清空二级机构的数据
        this.getOrganList();
        // this.getArealist();
        this.getSubId(this.entNum, 3);
      }
      if (val == 2) {
        //当前选择是二级,清空三级机构的数据
        this.getSubId(this.entNum, 2);
      }
      this.$nextTick(() => {
        this.$refs["form"].clearValidate();
        this.$refs["form"].resetFields();
      });
      //   if (this.$refs["form"]) {

      //   }
    },
    handleExceed(files, fileList) {
      this.$message.warning(
        `当前限制选择 1 个文件，本次选择了 ${
          files.length
        } 个文件，共选择了 ${files.length + fileList.length} 个文件`
      );
    },
    //格式化数据为树形结构
    formatTreeData(data) {
      let pos = {};
      let tree = [];
      let i = 0;
      while (data.length != 0) {
        if (data[i].parentId == 0) {
          //   tree.push({
          //     ...data[i],
          //     children: []
          //   });
          //   //   tree.push(data[i],...{
          //   //     children: []
          //   //   });
          //   pos[data[i].id] = [tree.length - 1];
          //   data.splice(i, 1);
          //   i--;
          data.ssplice(i, 1);
        } else {
          let posArr = pos[data[i].parentId];
          if (posArr != undefined) {
            let obj = tree[posArr[0]];
            for (let j = 1; j < posArr.length; j++) {
              obj = obj.children[posArr[j]];
            }

            obj.children.push({
              ...data[i],
              children: []
            });
            pos[data[i].id] = posArr.concat([obj.children.length - 1]);
            data.splice(i, 1);
            i--;
          }
        }
        i++;
        if (i > data.length - 1) {
          i = 0;
        }
      }
      return tree;
    },
    orderByFunc(val) {
      alert("排序");
      alert(val);
    },
    //编辑
    updateFunc(m) {
      this.billShow = true;
      this.title = "编辑机构";
      console.log(m, "45544");
      this.form = {
        addOrUpdate: "2", //新增或是编辑 1新增2编辑
        level: "2",
        name: "",
        id: "",
        area: [],
        parentId: "",
        subid: ""
      };
      if (m.level == 3) {
        this.getArealist();
        this.getOrganList();
      }
      if (m.level == 2) {
        this.getOperate();
      }
      fetchEditInfo(m.id).then(response => {
        console.log(response.data.data);
        this.$nextTick(() => {
          this.form = { ...this.form, ...response.data.data };
          delete this.form.childOrgan;
          this.form.level += "";
          this.form.area = [
            response.data.data.provinceId,
            response.data.data.cityId,
            response.data.data.countyId
          ];
          this.operate = this.form.isSub == 1 ? true : false;
          console.log(this.form, "000");
          // if (this.$refs["form"]) {
          //   this.$refs["form"].resetFields();
          // }
          this.$nextTick(() => {
            //等待dom同步后打开模态框
            this.$refs["form"].clearValidate();
            //this.$refs["form"].resetFields(); //此方法需要模态框加载完成后才可以执行
          });
        });
      })
      .catch(err => {});

      this.dialogFormVisible = true;
    },
    // filterMethod(val){
    //   console.log("valllll",val)
    //   this.form.operateId = val;
    //   if(val){
    //     this.operateOptions = this.optionsCopy.filter((item) => {
    //       console.log("item",item);
    //       if (!!~item.operateId.indexOf(val) || !!~item.operateName.indexOf(val)) {
    //         return true
    //       }
    //     })
    //   }else { //val为空时，还原数组
    //     this.operateOptions = this.optionsCopy;
    //   }
    // },
    checkVlue() {
      let vm = this;
      this.$refs["form"].validate(valid => {
        console.log(valid, vm.form, 454545);
        if (!valid) {
          console.log("error submit!!");
          return false;
        }
        if (this.form.level == 2) {
          if (
            valid &&
            !vm.form.chargeType &&
            vm.form.addOrUpdate == 1 &&
            vm.operate
          ) {
            this.$message({
              type: "info",
              message: "请选择计费企业生成方式"
            });
            return false;
          }
          if (
            valid &&
            vm.form.chargeType == 1 &&
            vm.form.addOrUpdate == 1 &&
            vm.operate
          ) {
            vm.form.chargeNum = "";
            vm.form.chargeEntName = "";
          }
          if (
            valid &&
            vm.form.chargeType == 2 &&
            !vm.form.chargeNum &&
            vm.form.addOrUpdate == 1 &&
            vm.operate
          ) {
            this.$message({
              type: "info",
              message: "请选择已有计费企业"
            });
            return false;
          }
          if (
            valid &&
            vm.form.chargeType == 3 &&
            !vm.form.chargeNum &&
            vm.form.addOrUpdate == 1 &&
            vm.operate
          ) {
            this.$message({
              type: "info",
              message: "请输入计费企业ID"
            });
            return false;
          }
          if (
            valid &&
            vm.form.chargeType == 3 &&
            !vm.form.chargeEntName &&
            vm.form.addOrUpdate == 1 &&
            vm.operate
          ) {
            this.$message({
              type: "info",
              message: "请输入计费名称"
            });
            return false;
          }
        }

        this.save();
      });
    },
    //保存
    save() {
      console.log(this.form.area);
      const array = this.form.area;
      this.billEntOptions.forEach(Element => {
        if (Element.chargeNum == this.form.chargeNum) {
          //console.log("this.form.chargeEntName")
          this.form.chargeEntName = Element.chargeEntName;
        }
      });
      let provinceId, countyId, cityId;
      const postData = {
        ...this.form,
        ...{
          entNum: this.entNum,
          isSub: this.operate ? "1" : "2"
        },
        ...{
          area: "",
          provinceId: array[0] || 0,
          cityId: array[1] || 0,
          countyId: array[2] || 0
        }
      };
      console.log(postData);
      this.axios
        .post("admin/ent/organ/save", Qs.stringify(postData), {
          headers: { "Content-Type": "application/x-www-form-urlencoded" }
        })
        .then(response => {
          console.log(response.data.data);
          this.$nextTick(() => {
            if (response.data.code == 0) {
              this.dialogFormVisible = false;
              this.$message({
                message: response.data.msg,
                type: "success"
              });
              this.getTreeData();
            } else {
              this.$message({
                message: response.data.msg,
                type: "error"
              });
            }
          });
        });
    },
    //删除
    deleteFunc(m) {
      this.axios
        .post("admin/ent/organ/delete?id=" + m.id + "&level=" + m.level)
        .then(response => {
          this.$nextTick(() => {
            console.log(response.data.data);
            if (response.data.code == 0) {
              this.$message({
                message: response.data.msg,
                type: "success"
              });
              this.getTreeData();
            } else {
              this.$message({
                message: response.data.msg,
                type: "error"
              });
            }
          });
        });
    },
    handlerExpand(m) {
      console.log("展开/收缩");
      m.isExpand = !m.isExpand;
    },
    getOperate() {
      this.axios.post("/admin/ent/organ/operate", {}).then(response => {
        console.log("response", response);
        this.operateOptions = response.data.data;
        this.optionsCopy = this.operateOptions;
      });
    },
    //序列化
    serialize(data) {
      let arr = [];
      for (let key in data) {
        arr.push(key + "=" + data[key]);
      }
      return arr.join("&");
    },
    //导出机构表
    exportFn() {
      let obj = {
        entNum: this.entNum
      };
      window.open("/admin/ent/organ/export?" + this.serialize(obj));
    },
    billChange() {
      if (this.form.chargeType == 2) {
        this.axios
          .post("/admin/enterprise/getChargeEntInfo", {})
          .then(response => {
            if (response.data.code == 0) {
              this.billEntOptions = response.data.data;
            }
          });
      }
    }
  }
};
</script>

<style lang="scss" scoped>
header {
  text-align: left;
  font-size: 16px;
  height: 40px;
  line-height: 40px;
  background: rgb(242, 242, 242);
  padding-left: 15px;
  a {
    color: blue;
    text-decoration: none;
    cursor: pointer;
  }
  .header-group {
    display: flex;
    flex-flow: row nowrap;
    justify-content: space-between;
    .icon{
      cursor: pointer;
      font-size: 18px;
    }
  }
}
.line {
  height: 5px;
  background: #fff;
  width: 100%;
  // margin-top: -14px;
}
.contains {
  width: 100%;
  margin: 30px 30px;
}
.el-header {
  background-color: #ffffff;
  color: #333;
  /* text-align: center; */
  line-height: 60px;
}
.el-dialog {
  width: 600px;
}
body > .el-container {
  margin-bottom: 40px;
}
.el-dialog__body {
  padding: 5px 20px;
  height: 350px;
  overflow: auto;
}
.el-form-item {
  margin-bottom: 15px;
}
</style>
